{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Armstrong Number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isArmstrong"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #阿姆斯特朗数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个整数 <code>n</code>&nbsp;，让你来判定他是否是<strong>&nbsp;</strong><strong>阿姆斯特朗数</strong>，是则返回 <code>true</code>，不是则返回 <code>false</code>。</p>\n",
    "\n",
    "<p>假设存在一个 <code>k</code> 位数 <code>n</code>&nbsp;，其每一位上的数字的 <code>k</code> 次幂的总和也是 <code>n</code>&nbsp;，那么这个数是阿姆斯特朗数 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>n = 153\n",
    "<strong>输出：</strong>true\n",
    "<strong>示例： </strong>\n",
    "153 是一个 3 位数，且 153 = 1<sup>3</sup> + 5<sup>3</sup> + 3<sup>3</sup>。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>n = 123\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>123 是一个 3 位数，且 123 != 1<sup>3</sup> + 2<sup>3</sup> + 3<sup>3</sup> = 36。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= n &lt;= 10<sup>8</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [armstrong-number](https://leetcode.cn/problems/armstrong-number/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [armstrong-number](https://leetcode.cn/problems/armstrong-number/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['153', '123']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        nums = []\n",
    "        copy = n\n",
    "        i = 0\n",
    "        len = 1\n",
    "        while n > 10:\n",
    "            len += 1\n",
    "            num = n % 10\n",
    "            nums.append(num)\n",
    "            n = n - (num * 10 ** i)\n",
    "            n = int(n / 10)\n",
    "\n",
    "        nums.append(n)\n",
    "        res = 0\n",
    "        for i in nums:\n",
    "            res += i ** len\n",
    "\n",
    "        if res == copy:\n",
    "            return True\n",
    "        return False\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        s = str(n)\n",
    "        m = len(s)\n",
    "        ans = 0\n",
    "        for x in s:\n",
    "            ans += pow(int(x), m)\n",
    "        return ans == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        l = len(str(n))\n",
    "        sum = 0\n",
    "        for i in str(n):\n",
    "            sum += int(i) ** l\n",
    "\n",
    "        return sum == n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "\n",
    "        t=n\n",
    "        count=0\n",
    "        while t:\n",
    "            t//=10\n",
    "            count+=1\n",
    "        print(count)\n",
    "        ans=0\n",
    "        k=n\n",
    "        while n:\n",
    "            t=n%10\n",
    "            ans+=t**count\n",
    "            n//=10\n",
    "        print(ans)\n",
    "        return True if k==ans else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        target = n\n",
    "        m = len(str(n))\n",
    "        while n:\n",
    "            target -= (n % 10) ** m\n",
    "            n //= 10\n",
    "        return target == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        return sum([int(i) ** len(str(n)) for i in str(n)]) == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        ll = len(str(n))\n",
    "        tot = 0\n",
    "        for i in str(n):\n",
    "            tot += pow(int(i),ll)\n",
    "        return tot == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        k = len(str(n))\n",
    "        a = reduce(operator.add, [int(x)**k for x in str(n)])\n",
    "        return a == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        return sum(int(i)**len(str(n)) for i in str(n))==n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        l = len(str(n))\n",
    "        m = n\n",
    "        d = 0\n",
    "        while m > 0:\n",
    "            d += (m % 10) ** l\n",
    "            m = m // 10\n",
    "        return True if d == n else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        ans = 0\n",
    "        x = n\n",
    "\n",
    "        k = 0\n",
    "        while x:\n",
    "            x = x // 10\n",
    "            k += 1\n",
    "        \n",
    "        x = n\n",
    "        while x:\n",
    "            a = x % 10\n",
    "            ans += a ** k\n",
    "            x = x // 10\n",
    "\n",
    "        return ans == n\n",
    "\n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        n = str(n)\n",
    "        k = len(n)\n",
    "        s = 0\n",
    "        for digit in n:\n",
    "            s+=pow(int(digit), k)\n",
    "        return s == int(n)\n",
    "\n",
    "        \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        res,n1 = 0,n\n",
    "        k = len(str(n))\n",
    "        while n1:\n",
    "            res+=(n1%10)**k\n",
    "            n1//=10\n",
    "        return res==n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        s = str(n)\n",
    "        k = len(s)\n",
    "        return n==sum(math.pow(int(x),k) for x in s) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        return self.answer_1(n)\n",
    "\n",
    "    def answer_1(self, n):\n",
    "        result = 0\n",
    "        times = 0\n",
    "\n",
    "        original_n = compute_times_n = compute_result_n = n\n",
    "\n",
    "        while compute_times_n:\n",
    "            times += 1\n",
    "            compute_times_n = compute_times_n // 10\n",
    "\n",
    "        while compute_result_n:\n",
    "            result += (compute_result_n % 10) ** times\n",
    "\n",
    "            compute_result_n = compute_result_n // 10\n",
    "        return result == original_n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "      k = len(str(n))\n",
    "      cnt, num = 0, n\n",
    "      while cnt < num and n:\n",
    "        cnt += (n % 10) ** k\n",
    "        n //= 10\n",
    "      return cnt == num and n == 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        k = len(str(n))\n",
    "        s_n = str(n)\n",
    "        s = 0\n",
    "        for i in range(k):\n",
    "            res = int(s_n[i])\n",
    "            # print(res)\n",
    "            s +=res**k\n",
    "        return s==n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        def calculate(n, k):\n",
    "            res = 0\n",
    "            while n > 0:\n",
    "                res += (n%10)**k\n",
    "                n //= 10\n",
    "            return res\n",
    "        \n",
    "        temp = n\n",
    "        k = 0\n",
    "        while temp > 0:\n",
    "            temp //= 10\n",
    "            k += 1\n",
    "        return n == calculate(n, k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        n_l = []\n",
    "        m = n \n",
    "        while m >= 1:\n",
    "            n_l.insert(0, m%10)\n",
    "            m //= 10\n",
    "        sums = 0\n",
    "        for i in n_l:\n",
    "            sums += i**len(n_l)\n",
    "        return n == sums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        sum = 0\n",
    "        k = len(str(n))\n",
    "        tmp=n\n",
    "        while tmp:\n",
    "            i = tmp % 10\n",
    "            sum += int(i) ** k\n",
    "            tmp = tmp // 10\n",
    "        return sum == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        new_n = n\n",
    "        length = len(str(new_n))\n",
    "        count = []\n",
    "        target = 0\n",
    "        for i in range(length):\n",
    "            count.append(new_n%10)\n",
    "            new_n = new_n//10\n",
    "        for i in count:\n",
    "            target += i**length\n",
    "        if target == n:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def isArmstrong(self, n: int) -> bool:\n",
    "#         sum = 0\n",
    "#         k = len(str(n))\n",
    "#         tmp=n\n",
    "#         while tmp:\n",
    "#             i = tmp % 10\n",
    "#             sum += int(i) ** k\n",
    "#             tmp = tmp // 10\n",
    "#         return sum == n\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        ans=0\n",
    "        m=n\n",
    "        l=len(str(n))\n",
    "        while n>0:\n",
    "            t=n%10\n",
    "            n=n//10\n",
    "            ans+=t**l\n",
    "        return ans==m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        str_n = str(n)\n",
    "        k = len(str_n)\n",
    "        n_sum = 0\n",
    "        for i in range(k):\n",
    "            n_sum += int(str_n[i])**k\n",
    "        # print(n_sum, str_n)\n",
    "        return n_sum == n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        s = 0\n",
    "        k = len(str(n))\n",
    "        for i in str(n):\n",
    "            s += int(i) ** k\n",
    "        return s == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "       return sum([int(i)**len(str(n)) for i in str(n)])==n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        s = str(n)\n",
    "        k = len(s)\n",
    "        ans = 0\n",
    "        for ch in s:\n",
    "            ans += int(ch) ** k\n",
    "        return ans == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        N = str(n)\n",
    "        k = len(N)\n",
    "        sum =0\n",
    "        for i in N:\n",
    "            sum+=int(i)**k\n",
    "        return sum == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, N: int) -> bool:\n",
    "        n = N\n",
    "        k = 0\n",
    "        while n:\n",
    "            k += 1\n",
    "            n //= 10\n",
    "        res = 0\n",
    "        n = N\n",
    "        while n:\n",
    "            cur = n % 10\n",
    "            res += cur**k\n",
    "            n //= 10\n",
    "\n",
    "        return res == N\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> (int, int):\n",
    "        tot_sum = 0\n",
    "        k = 1\n",
    "        temp_n = n\n",
    "        temp_n_2 = n\n",
    "        while temp_n // 10 > 0:\n",
    "            k += 1\n",
    "            temp_n = temp_n // 10\n",
    "        while n // 10 > 0:\n",
    "            tot_sum += pow(n%10, k)\n",
    "            n = n // 10\n",
    "        tot_sum += pow(n, k)\n",
    "        if tot_sum == temp_n_2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        nums , k  =[] ,n\n",
    "        while  k > 0 :\n",
    "            nums.append(int(k%10))\n",
    "            k=int(k/10)\n",
    "        l =len(nums)\n",
    "        sum =0\n",
    "        print(nums)\n",
    "        for i in nums:\n",
    "            sum+=i**l\n",
    "        return sum == n\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        k=0\n",
    "        n1=n\n",
    "        ans=[]\n",
    "        while(n):\n",
    "            ans.append(n%10)\n",
    "            n=n//10\n",
    "            k+=1\n",
    "        t=0\n",
    "        for i in ans:\n",
    "            t+=i**k\n",
    "        return t==n1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        nums = []\n",
    "        copy = n\n",
    "        i = 0\n",
    "        len = 1\n",
    "        while n > 10:\n",
    "            len += 1\n",
    "            num = n % 10\n",
    "            nums.append(num)\n",
    "            n = n - (num * 10 ** i)\n",
    "            n = int(n / 10)\n",
    "\n",
    "        nums.append(n)\n",
    "        res = 0\n",
    "        for i in nums:\n",
    "            res += i ** len\n",
    "\n",
    "        if res == copy:\n",
    "            return True\n",
    "        return False\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        sum = 0\n",
    "        k = len(str(n))\n",
    "        for i in str(n):\n",
    "            sum += int(i) ** k\n",
    "        return sum == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        nums = [int(d) for d in str(n)]\n",
    "        return sum(d ** len(nums) for d in nums) == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        k = len(str(n))\n",
    "        res = 0\n",
    "        for i in str(n):\n",
    "            res += int(i) ** k\n",
    "        if res == n:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        nums = []\n",
    "        copy = n\n",
    "        i = 0\n",
    "        len = 1\n",
    "        while n > 10:\n",
    "            len += 1\n",
    "            num = n % 10\n",
    "            nums.append(num)\n",
    "            n = n - (num * 10 ** i)\n",
    "            n = int(n / 10)\n",
    "\n",
    "        nums.append(n)\n",
    "        res = 0\n",
    "        for i in nums:\n",
    "            res += i ** len\n",
    "\n",
    "        if res == copy:\n",
    "            return True\n",
    "        return False\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        # \n",
    "        k = len(str(n))\n",
    "        count = 0\n",
    "        for i in range(k):\n",
    "            count += pow(int(str(n)[i]),k)\n",
    "        if count == n:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        l = []\n",
    "        n_tmp=n\n",
    "        while n_tmp:\n",
    "            l.append(n_tmp%10)\n",
    "            n_tmp//=10\n",
    "        return sum([item**len(l) for item in l])==n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        s=str(n)\n",
    "        sums=0\n",
    "        k=len(s)\n",
    "        for i in s:\n",
    "            sums += int(i)**k\n",
    "        if sums==n:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        n = str(n)\n",
    "        k = len(n)\n",
    "        s = 0\n",
    "        for digit in n:\n",
    "            s += int(digit)**k\n",
    "        return s == int(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        N = str(n)\n",
    "        k = len(N)\n",
    "        sum =0\n",
    "        for i in range(k):\n",
    "            sum+=int(N[i])**k\n",
    "            # sum+=int(i)**k\n",
    "        return sum == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        arr = list(map(int,str(n)))\n",
    "        count = 0\n",
    "        curr = 1\n",
    "        for i in range(len(arr)):\n",
    "            for j in range(len(arr)):\n",
    "                curr *= arr[i]\n",
    "            count += curr\n",
    "            curr = 1\n",
    "        return count == n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        sums = 0\n",
    "        k = len(str(n))\n",
    "        b = n\n",
    "        while n:\n",
    "            a  = n % 10\n",
    "            n //= 10\n",
    "            sums += a**k\n",
    "        return sums == b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        res = 0\n",
    "        k = len(str(n))\n",
    "        for i in str(n):\n",
    "            res+=int(i)**k\n",
    "        return res==n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        strn = str(n)\n",
    "        k = len(strn)\n",
    "        sumn = 0\n",
    "        for num in strn:\n",
    "            num = int(num)\n",
    "            sumn += (num**k)\n",
    "        if sumn == n:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        sum=0\n",
    "        for i in str(n):\n",
    "            sum+=int(i)**len(str(n))\n",
    "            if sum>n:\n",
    "                return False\n",
    "        if sum==n:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        k = len(str(n))\n",
    "        num = 0\n",
    "        p = n\n",
    "        while n:\n",
    "            w = n%10\n",
    "            n = n//10\n",
    "            num+=w**k\n",
    "        return p == num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isArmstrong(self, n: int) -> bool:\n",
    "        k = len(str(n))\n",
    "        return sum(int(x)**k for x in str(n)) == n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
